package com.studentManager;

import com.arrlist.Students;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;



public class StudentManager {

    public static void main(String[] args) {

        ArrayList<Student> students = new ArrayList<Student>();
        System.out.println("--------------欢迎来到学生管理系统-------------");
        System.out.println("1  添加学生");
        System.out.println("2  删除学生");
        System.out.println("3  修改学生");
        System.out.println("4  查看所有学生");
        System.out.println("5  退出");

        String type = "0";


        while (type!="5"){
            switch (type){
                case "0":
                    System.out.println("请选择功能");
                    Scanner scanner = new Scanner(System.in);
                    type = scanner.nextLine();
                    break;
                case "1":
                    addStudent(students);
                    type = "0";
                    break;
                case "2":
                    System.out.println("请输入删除学生学号");
                    Scanner scanner6 = new Scanner(System.in);
                    String sidd = scanner6.next();
                    if(delStudent(students,sidd)){
                        System.out.println("删除成功!");
                        type = "0";
                    }else{
                        System.out.println("删除失败!");
                        type = "2";
                    }
                    break;
                case "3":
                    Scanner scanner7 = new Scanner(System.in);
                    type = scanner7.nextLine();
                    break;
                case "4":
                    System.out.println(getStudents(students));
                    type = "0";
                    break;
                default:
                    System.out.println("谢谢使用!");
                    type = "5";
            }
        }


    }
    //增加学生
    public static void addStudent(ArrayList<Student> students){
        System.out.println("请输入学号");
        Scanner scanner = new Scanner(System.in);
        String sid = scanner.nextLine();
        System.out.println("请输入姓名");
        String sname = scanner.nextLine();
        System.out.println("请输入年龄");
        int sage = Integer.valueOf(scanner.nextLine()).intValue();
        System.out.println("请输入地址");
        String saddress = scanner.nextLine();
        students.add(new Student(sid,sname,sage,saddress));
        System.out.println("添加成功!");
    }
    //删除学生
    public static boolean delStudent(ArrayList<Student> students,String sid){
        System.out.println(sid);
        for(int i=0;i<students.size();i++){
            if(students.get(i).getSid().equals(sid)){
                students.remove(i);
                return true;
            }
        }
        return false;
    }
//    //修改学生
//    public static void editStudent(ArrayList<Student> students,int i){
//        students.set(student);
//    }
    //查询学生
    public static String getStudents(ArrayList<Student> students){
        StringBuilder res = new StringBuilder("学号           姓名           年龄           居住地\n");

        for(int i=0;i<students.size();i++){
            Student student = students.get(i);
            res.append(student.getSid()+"           "+
                    student.getSname()+"           "+
                    student.getSage()+"           "+
                    student.getSaddress()+"\n");
        }
        return  res.toString();
    }
}
